package com.zc.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.blog.mapper.ArticleMapper;
import com.zc.blog.mapper.TagArticleMapper;
import com.zc.blog.model.Article;
import com.zc.blog.model.PageBean;
import com.zc.blog.model.Tag;
import com.zc.blog.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户Service实现类
 */
@Service("ArticleService")
public class IArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Value("${topHot}")
    private int topHot;

    @Override
    public Article findById(Integer id) {
        return articleMapper.findById(id);
    }

    @Override
    public List<Article> listAll(Integer page, Integer pageSize,String query) {
        int start = (page - 1) * pageSize;
        return articleMapper.listAll(start,pageSize,query);
    }

    @Override
    public List<Article> listCategoryArticles(Integer page, Integer pageSize, String query, Integer categoryId) {
        int start = (page - 1) * pageSize;
        return articleMapper.listCategoryArticles(start,pageSize,query,categoryId);
    }

    @Override
    public List<Article> listTagArticles(Integer page, Integer pageSize, String query, Integer tagId) {
        int start = (page - 1) * pageSize;
        return articleMapper.listTagArticles(start,pageSize,query,tagId);
    }

    @Override
    public Integer getTotal(String query) {
        return articleMapper.getTotal(query);
    }

    @Override
    public Integer getCategoryArticlesTotal(String query, Integer categoryId) {
        return articleMapper.getCategoryArticlesTotal(query,categoryId);
    }

    @Override
    public Integer getTagArticlesTotal(String query, Integer tagId) {
        return articleMapper.getTagArticlesTotal(query,tagId);
    }

    @Override
    public List<Tag> findArticlesByTagId(Integer tagId) {
        return articleMapper.findArticlesByTagId(tagId);
    }

    @Override
    public List<Article> findArticlesBySlider() {
        return articleMapper.findArticlesBySlider();
    }

    @Override
    public void incrementClick(Integer id) {
        articleMapper.incrementClick(id);
    }

    @Override
    public List<Article> findHotArticles() {
        return articleMapper.findHotArticles(topHot);
    }

    @Override
    public List<Article> findArticlesByCategoryId(Integer categoryId) {
        return articleMapper.findArticlesByCategoryId(categoryId);
    }


}
